package com.example.kakaotalk;

import java.util.List;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;

public class MyAdapter extends BaseAdapter {
	public static final int ITEM_VIEW_TYPE_ONE = 0;
	public static final int ITEM_VIEW_TYPE_SEND = 1;
	public static final int ITEM_VIEW_COUNT = 2;
	
	List<MyData> mList;
	Context mContext;
	
	public MyAdapter(Context context, List<MyData> list){
		mContext = context;
		mList = list;
	}
	
	@Override
	public int getCount(){
		return mList.size();
	}
	
	@Override
	public MyData getItem(int position){
		return mList.get(position);
	}
	
	@Override
	public long getItemId(int position){
		return position;
	}
	
	@Override
	public View getView(int position,View convertView, ViewGroup parent){
		MyData data = mList.get(position);
		if(data.isSend == false){
			MyItemView view;
			view = new MyItemView(mContext);
			view.setData(data);
			return view;
		}else{
			MyItemSendView view;
			if(convertView == null){
				view = new MyItemSendView(mContext);
			}else{
				view = (MyItemSendView) convertView;
			}
			view.setData(data);
			return view;
		}
	}
	
	@Override
	public int getViewTypeCount(){
		return ITEM_VIEW_COUNT;
	}
	
	@Override
	public int getItemViewType(int position){
		MyData data = mList.get(position);
		if(data.isSend == true)
			return ITEM_VIEW_TYPE_SEND;
		else
			return ITEM_VIEW_TYPE_ONE;
	}
	
	public void add(MyData myData){
		mList.add(myData);
		notifyDataSetChanged();
	}
}
